(function(factory) {
	if(typeof define === "function" && define.amd) {

		// AMD. Register as an anonymous module.
		define(factory);
	} else {
		// Browser globals
		factory();
	}
}(function() {
	/**
	 * 用户UA检测工具
	 * @class HteOS.UA
	 * @singleton
	 * */
	HteOS.UA = {
		init: function(navigator) {
			var platforms = this.platforms,
				ln = platforms.length,
				i, platform;

			navigator = navigator || window.navigator;

			for(i = 0; i < ln; i++) {
				platform = platforms[i];
				this[platform.identity] = platform.regex.test(navigator[platform.property]);
			}

			/**
			 * @property Desktop True if the browser is running on a desktop machine
			 * @type {Boolean}
			 */
			this.Desktop = this.Mac || this.Windows || (this.Linux && !this.Android);
			/**
			 * @property Tablet True if the browser is running on a tablet (iPad)
			 */
			this.Tablet = this.iPad;
			/**
			 * @property Phone True if the browser is running on a phone.
			 * @type {Boolean}
			 */
			this.Phone = !this.Desktop && !this.Tablet;
			/**
			 * @property iOS True if the browser is running on iOS
			 * @type {Boolean}
			 */
			this.iOS = this.iPhone || this.iPad || this.iPod;

			/**
			 * @property 判断是否是移动端
			 * @type {Boolean}
			 * */
			this.Mobile = this.iOS || this.Android;

			/**
			 * @property Standalone Detects when application has been saved to homescreen.
			 * @type {Boolean}
			 */
			this.Standalone = !!window.navigator.standalone;

			/**
			 * @property iOS True if the browser support css3 transform
			 * @type {Boolean}
			 */
			this.CSS3Transform = ('transform' in document.documentElement.style);

			var userAgent = window.navigator.userAgent.toLowerCase(),
				check = function(
					regex) {
					return regex.test(userAgent);
				},
				isStrict = document.compatMode == "CSS1Compat",
				version = function(is,
					regex) {
					var m;
					return(is && (m = regex.exec(userAgent))) ? parseFloat(m[1]) : 0;
				},

				docMode = document.documentMode,
				isOpera = check(/opera/),
				isOpera10_5 = isOpera && check(/version\/10\.5/),
				isChrome = check(/\bchrome\b/),
				isWebKit = check(/webkit/),
				isSafari = !isChrome && check(/safari/),
				isSafari2 = isSafari && check(/applewebkit\/4/), // unique
				// to
				// Safari
				// 2
				isSafari3 = isSafari && check(/version\/3/),
				isSafari4 = isSafari && check(/version\/4/),
				isSafari5_0 = isSafari && check(/version\/5\.0/),
				isSafari5 = isSafari && check(/version\/5/),
				isIE = !isOpera && check(/msie/),
				isIE7 = isIE && ((check(/msie 7/) && docMode != 8 && docMode != 9 && docMode != 10) || docMode == 7),
				isIE8 = isIE && ((check(/msie 8/) && docMode != 7 && docMode != 9 && docMode != 10) || docMode == 8),
				isIE9 = isIE && ((check(/msie 9/) && docMode != 7 && docMode != 8 && docMode != 10) || docMode == 9),
				isIE10 = isIE && ((check(/msie 10/) && docMode != 7 && docMode != 8 && docMode != 9) || docMode == 10),
				isIE6 = isIE && check(/msie 6/),
				isGecko = !isWebKit && check(/gecko/),
				isGecko3 = isGecko && check(/rv:1\.9/),
				isGecko4 = isGecko && check(/rv:2\.0/),
				isGecko5 = isGecko && check(/rv:5\./),
				isGecko10 = isGecko && check(/rv:10\./),
				isFF3_0 = isGecko3 && check(/rv:1\.9\.0/),
				isFF3_5 = isGecko3 && check(/rv:1\.9\.1/),
				isFF3_6 = isGecko3 && check(/rv:1\.9\.2/),
				isWindows = check(/windows|win32/),
				isMac = check(/macintosh|mac os x/),
				isLinux = check(/linux/),
				scrollbarSize = null,
				chromeVersion = version(
					true, /\bchrome\/(\d+\.\d+)/),
				firefoxVersion = version(true,
					/\bfirefox\/(\d+\.\d+)/),
				ieVersion = version(isIE,
					/msie (\d+\.\d+)/),
				operaVersion = version(isOpera,
					/version\/(\d+\.\d+)/),
				safariVersion = version(isSafari,
					/version\/(\d+\.\d+)/),
				webKitVersion = version(isWebKit,
					/webkit\/(\d+\.\d+)/),
				isSecure = /^https/i
				.test(window.location.protocol),
				nullLog;

			this.docMode = docMode;
			this.isOpera = isOpera;
			this.isOpera10_5 = isOpera10_5;
			this.isChrome = isChrome;
			this.isWebKit = isWebKit;
			this.isSafari = isSafari;
			this.isSafari2 = isSafari2;
			this.isSafari3 = isSafari3;
			this.isSafari4 = isSafari4;
			this.isSafari5_0 = isSafari5_0;
			this.isSafari5 = isSafari5;
			this.isIE = isIE;
			this.isIE7 = isIE7;
			this.isIE8 = isIE8;
			this.isIE9 = isIE9;
			this.isIE10 = isIE10;
			this.isIE6 = isIE6;
			this.isGecko = isGecko;
			this.isGecko3 = isGecko3;
			this.isGecko4 = isGecko4;
			this.isGecko5 = isGecko5;
			this.isGecko10 = isGecko10;
			this.isFF3_0 = isFF3_0;
			this.isFF3_5 = isFF3_5;
			this.isWindows = isWindows;
			this.isMac = isMac;
			this.isLinux = isLinux;
			this.chromeVersion = chromeVersion;
			this.firefoxVersion = firefoxVersion;
			this.ieVersion = ieVersion;
			this.operaVersion = operaVersion;
			this.safariVersion = safariVersion;
			this.webKitVersion = webKitVersion;

			this.advance = (!this.isIE6 && !this.isIE7 && !this.isIE8);
			this.livedd = false; // 实时展现拖拽效果
			try {
				document.execCommand("BackgroundImageCache", false, true);
			} catch(e) {}
		},

		/**
		 * @property iPhone True when the browser is running on a iPhone
		 * @type {Boolean}
		 */
		platforms: [{
				property: 'platform',
				regex: /iPhone/i,
				identity: 'iPhone'
			},

			/**
			 * @property iPod True when the browser is running on a iPod
			 * @type {Boolean}
			 */
			{
				property: 'platform',
				regex: /iPod/i,
				identity: 'iPod'
			},

			/**
			 * @property iPad True when the browser is running on a iPad
			 * @type {Boolean}
			 */
			{
				property: 'userAgent',
				regex: /iPad/i,
				identity: 'iPad'
			},

			/**
			 * @property Blackberry True when the browser is running on a Blackberry
			 * @type {Boolean}
			 */
			{
				property: 'userAgent',
				regex: /Blackberry/i,
				identity: 'Blackberry'
			},

			/**
			 * @property Android True when the browser is running on an Android device
			 * @type {Boolean}
			 */
			{
				property: 'userAgent',
				regex: /Android/i,
				identity: 'Android'
			},

			/**
			 * @property Mac True when the browser is running on a Mac
			 * @type {Boolean}
			 */
			{
				property: 'platform',
				regex: /Mac/i,
				identity: 'Mac'
			},

			/**
			 * @property Windows True when the browser is running on Windows
			 * @type {Boolean}
			 */
			{
				property: 'platform',
				regex: /Win/i,
				identity: 'Windows'
			},

			/**
			 * @property Linux True when the browser is running on Linux
			 * @type {Boolean}
			 */
			{
				property: 'platform',
				regex: /Linux/i,
				identity: 'Linux'
			}
		]
	};
	HteOS.UA.init();
}));